package com.carrie.mdg.myviewtext.activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.carrie.mdg.myviewtext.R;
import com.carrie.mdg.myviewtext.utils.Utils;

import androidLib.activity.BaseActivity;

/**
 * Created by mdg on 2017/3/23.
 */

public class TextActivity extends BaseActivity {
    private static final String TAG = "TextActivity";
    private int numb;
    private Button btn_view, btn_dial, btn_for_result, btn_dialog_activity;
    private static final int FOR_RESULT = 0;

    public static void actionStart(Context context, String data1, String data2) {
        Intent intent = new Intent(context, TextActivity.class);
        intent.putExtra("data1", data1);
        intent.putExtra("data2", data2);
        context.startActivity(intent);
    }

    @Override
    protected void initVariables() {
        Intent intent = getIntent();
        numb = Utils.convertToInt(intent.getStringExtra("number"), 0);
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setContentView(R.layout.activity_text_layout);
        if (savedInstanceState != null) {

        }
        btn_view = (Button) findViewById(R.id.button2);
        btn_dial = (Button) findViewById(R.id.button3);
        btn_for_result = (Button) findViewById(R.id.button4);
        btn_dialog_activity = (Button) findViewById(R.id.button6);
    }

    @Override
    protected void initEvent() {
        btn_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("http://www.baidu.com"));
                startActivity(intent);
            }
        });

        btn_dial.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:10086"));
                startActivity(intent);
            }
        });
        btn_for_result.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(TextActivity.this, TestForResultActivity.class);
                startActivityForResult(intent, FOR_RESULT);
            }
        });
        btn_dialog_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogActivity.actionStart(TextActivity.this, 0, "data2");
            }
        });
    }

    @Override
    protected void loadData() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case FOR_RESULT:
                if (resultCode == RESULT_OK && data != null) {
                    String backData = data.getStringExtra("back_data");
                }
                break;
        }
    }

    //Activity被回收之前一定会被调用，可以用来保存一些数据
    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
    }
}
